﻿using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Carto;

namespace MyEngineExercise.我的扩展
{
    internal sealed class Maps : IMaps, IDisposable
    {
        internal List<IMap> _mapList = null;

        public Maps()
        {
            _mapList = new List<IMap>();
        }

        #region IDisposable Members
        public void Dispose()
        {
            if(null != _mapList)
            {
                _mapList.Clear();
                _mapList = null;
            }
        }
        #endregion 


        #region IMaps Members
        public int Count
        {
            get { return _mapList.Count; }
        }

        public void Add(IMap Map)
        {
            if (null == Map)
                throw new Exception("Maps::Add:\r\nNew Map is mot initialized!");

            _mapList.Add(Map);
        }

        public IMap Create()
        {
            IMap newMap = new MapClass();
            _mapList.Add(newMap);
            return newMap;
        }

        public IMap get_Item(int Index)
        {
            if (Index > _mapList.Count || Index < 0)
                throw new Exception("Maps::get_Item:\r\nIndex is out of range!");
            return _mapList[Index] as IMap;
        }

        public void Remove(IMap Map)
        {
            _mapList.Remove(Map);
        }

        public void RemoveAt(int Index)
        {
            if (Index > _mapList.Count || Index < 0)
                throw new Exception("Maps::RemoveAt:\r\nIndex is out of range!");
            _mapList.RemoveAt(Index);
        }

        public void Reset()
        {
            _mapList.Clear();
        }
        #endregion
    }
}
